package com.letv.app.ljodfh.ui.adapter.holder;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;

import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.letv.app.ljodfh.R;
import com.letv.app.ljodfh.base.BaseActivity;
import com.letv.app.ljodfh.beans.LiveItem;
import com.letv.app.ljodfh.ui.activities.LivingActivity;
import com.letv.app.ljodfh.ui.utils.GlideUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by liuyu on 2017/7/14.
 */

public class LiveHomeItemHolder extends BaseAbsHolder<LiveItem> implements View.OnClickListener {

	@BindView(R.id.item_live_item_img)
	protected CustomEXImageView img;
	@BindView(R.id.item_live_list_mode)
	protected CustomFontTextView mode;
	@BindView(R.id.item_live_item_title)
	protected CustomFontTextView title;
	@BindView(R.id.item_live_label_date)
	protected CustomFontTextView date;
	@BindView(R.id.item_live_label_channel)
	protected CustomFontTextView channel;

	private LiveItem liveItem;

	public LiveHomeItemHolder(Context context, View itemView) {
		super(context, itemView);
		itemView.setOnClickListener(this);
	}
	@Override
	protected void initInject() {
		ButterKnife.bind(this, itemView);
	}

	@Override
	public void setData(LiveItem liveItem) {
		this.liveItem = liveItem;
		if (liveItem.isLiving()) {
			mode.setBackgroundResource(R.drawable.live_labei_bg);
			mode.setText(R.string.livinging);
		} else {
			mode.setBackgroundResource(R.drawable.live_review_bg);
			mode.setText(R.string.retrospect);
		}
		title.setText(liveItem.getTitle());
		date.setText(DateUtils.getDateStringForItem(DateUtils.getDataDate(liveItem)));
		channel.setText(liveItem.getLiveSource());
		GlideUtil.loadImgLarge169Def(context, liveItem.getLiveImg(), img);
//		if (!TextUtils.isEmpty(liveItem.getLiveImg())) {
//		}
	}

	@Override
	public void onClick(View v) {
		Intent intent = new Intent(context, LivingActivity.class);
//		if (liveItem != null && liveItem.isLiving()) {
		intent.putExtra(BaseActivity.EX_URL, liveItem.getLiveUrl());
		intent.putExtra(BaseActivity.EX_DATA, liveItem.getLiveImg());
//		}
		context.startActivity(intent);
	}
}
